﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/Basic.Master" AutoEventWireup="true" CodeBehind="BottleInfoList.aspx.cs" Inherits="PMS.UI.BD.BottleInfoList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            var height = $("#divTotal").height();
            var master = $("#master").height();
            var content = parseFloat(height) - parseFloat(master) - 30;
            $("#tbList").css("height", content);
        });
    </script>
    <script type="text/javascript">
        $(function () {
            //   $('#btnModify').linkbutton('disable');
            $("#tbList").datagrid({
                url: '/Logic/BD/BottleAjax.aspx?method=GetBottleList',
                loadMsg: '数据加载中请稍后……',
                fitColumns: false,
                pagination: true,
                queryParams: com.serializeSearchArray("form1"),
                rownumbers: true,
                idField: "ID",
                singleSelect: true,
                pageSize: 20,
                pageList: [20, 50, 100],
                striped: true,
                frozenColumns: [[{ field: 'ck', checkbox: true, width: 30 },
                 { field: 'ID', title: 'ID', align: "center" ,width: 40},
                 {
                     field: 'BottleCode', title: '气瓶编号 ', align: "center", width: 160, editor: {
                         type: "validatebox",
                         options: {
                             required: true
                         }
                     }
                 },
                 {
                     field: 'BottleAlloy', title: '材质', align: "center", width: 60, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 } ]],
                columns: [[
                 {
                     field: 'BottleVolume', title: '容积/L', align: "center", width: 60, editor: {
                         type: "validatebox",
                         options: {}
                     }},
                 {
                     field: 'ProductionDate', title: '生产日期', align: "center", sortable:true,width: 100, editor: {
                         type: "datebox",
                         options: {}
                     }
                 },
                 {
                     field: 'LastCheckDate', title: '上次质检日期', align: "center", sortable: true, width: 100, editor: {
                         type: "datebox",
                         options: {}
                     }
                 },
                  {
                      field: 'BottleSupplierID', title: '生产厂家', sortable: true, width: 100, align: "center", editor: {
                          type: "combobox",
                          options: {
                              url: '/Logic/BD/BottleSupplierAjax.aspx?method=GetBottleSupplierName',
                              valueField: 'value',
                              textField: 'text'
                              
                          }
                      }, formatter: function (value, row, index) {
                          return row.BottleSupplier;
                      }
                  },
                  {
                      field: 'MadeCode', title: '制造代码', align: "center", sortable: true, width: 100
                      
                  },
                {
                    field: 'Note', title: '备注', align: "center", width: 100, editor: {
                        type: "validatebox",
                        options: {}
                    }
                 }]],
                onAfterEdit: function (rowIndex, rowData, changes) {
                    if (editAction == "edit") {
                        com.ajax({
                            url: "/Logic/BD/BottleAjax.aspx?method=EditBottle",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    } else if (editAction == "add") {
                        com.ajax({
                            url: "/Logic/BD/BottleAjax.aspx?method=AddBottle",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    }
                    editRow = undefined;
                },
                onCancelEdit: function (rowIndex, rowData) {
                    $("#tbList").datagrid("rejectChanges");
                }
            });
        });

    </script>
    <script type="text/javascript">
        editRow = undefined;
        editAction = undefined;

        //添加
        function funcAdd() {
            //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
            if (editRow == undefined) {
                $("#tbList").datagrid("insertRow", {
                    index: 0,
                    row: {
                        BottleVolume:8
                    }
                });
                //将新插入的那一行开户编辑状态
                $("#tbList").datagrid("beginEdit", 0);
                //给当前编辑的行赋值
                editRow = 0;
                editAction = "add";
            }
        }

        //编辑
        function funcEdit() {
            var row = $('#tbList').datagrid('getSelected');

            if (row) {
                if (editRow != undefined) {
                }
                else {
                    var index = $("#tbList").datagrid('getRowIndex', row);
                    $("#tbList").datagrid('beginEdit', index);
                    editAction = "edit";
                    editRow = index;
                    rowData = $("#tbList").datagrid("getSelected");
                }
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        //查询
        function funcSearch() {
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);
            editRow = undefined;
            editAction = undefined;
        }

        //删除
        function funcRemove() {
            $.messager.confirm('确认对话框', '您确定删除该气瓶吗？', function (r) {
                if (r) {
                    var row = $('#tbList').datagrid('getSelected');
                    if (row) {
                        com.ajax({
                            url: "/Logic/BD/BottleAjax.aspx?method=DelBottle",
                            data: { ID: row.ID },
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); $('#tbList').datagrid('clearSelections'); })
                            }
                        });
                    }
                    else {
                        com.message("information", "请选中一行");
                    }
                }
            });
            editRow = undefined;
            editAction = undefined;
        }

        //取消编辑
        function funcCancel() {
            $('#tbList').datagrid("cancelEdit", editRow);
            editRow = undefined;
            editAction = undefined;
        }

        //重置
        function funcReload() {
            $("#form1").form("reset");
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);
            editRow = undefined;
            editAction = undefined;
        }

        function funcSave() {
            $('#tbList').datagrid('endEdit', editRow);
        }

        //导出
        function funcToExcel() {
            var para = com.serializeSearchArray1("form1");
            //列标题
            var cellhead = {
                "BottleCode": "瓶号", "ProductionDate": "生产日期", "LastCheckDate": "定期检验日期",
                "BottleSupplier": "生产厂家","MadeCode": "制造代码",  "Note": "备注"
            }
            var form = {};
            form['searchData'] = para;
            form['cellhead'] = JSON.stringify(cellhead);
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/Logic/BD/BottleAjax.aspx?method=BottleList2Excel",
                data: form,
                success: function (data) {
                    location.href = location.origin + '/' + data;
                }
            })
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="divTotal" style="height: 100%; width: 100%">
        <div id="master" class="container_16" style="height: auto">
            <form id="form1">
                <div class="grid_2 sealbl"  style="width:100px">
                    气瓶编号:
                </div>
                <div class="grid_2 seaval">
                    <input type="text" id="BottleCode" name="BottleCode"  data-cp="co" />
                </div>
               
                <div class="grid_2 sealbl" style="width:160px">
                    生产日期从年月:
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="startPrdDate" name="startPrdDate" data-cp="str>=" class="easyui-datebox" />
                </div>
                <div class="grid_2 sealbl">
                    到年月:
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="endPrdDate" name="endPrdDate" data-cp="str<=" class="easyui-datebox" />
                </div>
                <div class="Clear"></div>

                <div class="grid_2 sealbl" style="width:100px">
                    气瓶材质:
                </div>
                <div class="grid_2 seaval" >
                    <input type="text" id="BottleAlloy" name="BottleAlloy"  data-cp="co" />
                </div>
                <div class="grid_2 sealbl" style="width:160px">
                    质检日期从年月:
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="startChkDate" name="startChkDate" data-cp="str>=" class="easyui-datebox" />
                </div>
                <div class="grid_2 sealbl" >
                    到年月:
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="endChkDate" name="endChkDate" data-cp="str<=" class="easyui-datebox" />
                </div>
            </form>
        </div>
        <table id="tbList" title="气瓶信息表 " style="width: 100%">
        </table>
        <div id="assignCompanyDiv">
        </div>
    </div>
</asp:Content>
